import { createVNode,render} from "vue";
import ContextMenu from './ContextMenu.vue'
export interface ActionItem{
    action: (cid?: string) => void;
    text: string;
    shortcut: string;
}

const createContextMenu = (actions: ActionItem[], triggerClass='edit-wrapper')=> {
    const el = document.createElement('div');
    const options = {
        actions,
        triggerClass
    }
    const vm = createVNode(ContextMenu,options)
    render(vm,el)
    document.body.appendChild(el)

    //卸载函数式的组件, 用vue sfc是不会有这个问题的
    return ()=>{
        render(null,el)
        document.body.removeChild(el)
    }
}

export default createContextMenu